https://leetcode.cn/problems/design-circular-queue/


typedef struct {
    int* a;
    int front;
    int rear;
    int k;
} MyCircularQueue;


bool myCircularQueueIsEmpty(MyCircularQueue* obj) {
    return obj->front == obj->rear;
}

bool myCircularQueueIsFull(MyCircularQueue* obj) {
    if ((obj->rear + 1) % (obj->k + 1) == obj->front)
    {
        return true;
    }
    else
    {
        return false;
    }
}

void myCircularQueueFree(MyCircularQueue* obj) {
    free(obj->a);
    free(obj);
}

MyCircularQueue* myCircularQueueCreate(int k) {
    MyCircularQueue* pcq = (MyCircularQueue*)malloc(sizeof(MyCircularQueue));
    pcq->a = (int*)malloc(sizeof(int) * (k + 1));
    pcq->front = pcq->rear = 0;
    pcq->k = k;
    return pcq;
}

bool myCircularQueueEnQueue(MyCircularQueue* obj, int value) {
    if (myCircularQueueIsFull(obj))
    {
        return false;
    }
    else {
        obj->a[obj->rear] = value;
        obj->rear++;
        obj->rear %= (obj->k + 1);
        return true;
    }
}

bool myCircularQueueDeQueue(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
    {
        return false;
    }
    else {
        obj->front++;
        obj->front %= (obj->k + 1);
        return true;

    }
}

int myCircularQueueFront(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
    {
        return -1;
    }
    else {
        return obj->a[obj->front];
    }

}

int myCircularQueueRear(MyCircularQueue* obj) {
    if (myCircularQueueIsEmpty(obj))
    {
        return -1;
    }
    else {
        return obj->a[(obj->rear - 1 + obj->k + 1) % (obj->k + 1)];
    }
}
